package dna;

import core.inputoutput.formatting.Format;
import core.inputoutput.formatting.FormattedEntry;
import util.XYZPosition;

/**
 * A Formatted entry intended to parse through a PDB line containing information about a DNA molecule
 * @author Julian
 *
 */
public class AtomEntryDNA extends FormattedEntry {

	

	private Integer AtomIndex, //Atom index in molecule
				NucIndex, //Nucleoside index
				StrandID; //Numeric ID of strand - not always present
	
	private String AtomTag, //Atom string identifier, ex "1H2"
		   		   NucType, //Nucleoside type - A,C,T,G
		   		   AtomTypeAbbr,//Type of atom - C,N,H,P, etc.
		   		   StrandLabel; //String ID of strand - not always present
	
	private double X, //X coord
	 	   		   Y, //Y coord
	 	   		   Z, //Z coord
	 	   		   UK1, //TODO: Unknown value - always 1.00
	 	   		   UK2; //TODO: Unknown value - always 0.00
	
	
	

	public AtomEntryDNA(String line, Format f) {
		super(line, f);
	}

	//Getters for contents
	public int getAtomIndex() {
		return AtomIndex;
	}

	public int getNucIndex() {
		return NucIndex;
	}

	public String getAtomTag() {
		return AtomTag;
	}

	public String getNucType() {
		return NucType;
	}

	public String getAtomTypeAbbr() {
		return AtomTypeAbbr;
	}

	public double getX() {
		return X;
	}

	public double getY() {
		return Y;
	}

	public double getZ() {
		return Z;
	}

	public double getUK1() {
		return UK1;
	}

	public double getUK2() {
		return UK2;
	}


	@Override
	protected void assignVal(String substring, int colNum) {
		switch(colNum){
		case 0: break;//do nothing
		case 1: AtomIndex = Integer.parseInt(substring.trim());break;
		case 2: AtomTag = substring.trim();break;
		case 3: NucType = substring.trim();break;
		case 4: StrandLabel = substring.trim(); break;
		case 5: NucIndex = Integer.parseInt(substring.trim());break;
		case 6: X = Double.parseDouble(substring.trim());break;
		case 7: Y = Double.parseDouble(substring.trim());break;
		case 8: Z = Double.parseDouble(substring.trim());break;
		case 9: UK1 = Double.parseDouble(substring.trim());break;
		case 10: UK2 = Double.parseDouble(substring.trim());break;
		case 11: StrandID = substring.trim().length() > 0 ? parseStrandID(substring): null;break; //TODO: not the best way to get ID
		case 12: AtomTypeAbbr = substring.trim();break;
		}
	}


	private Integer parseStrandID(String strandID) {
		String s = "";
		for (int i = 0; i < strandID.length(); i++){
			if ((s = strandID.substring(i)).matches("\\d+") || (s = strandID.substring(0,i+1)).matches("\\d+"))
				return Integer.parseInt(s);
		}
		return null;
	}

	public Integer getStrandID() {
		return StrandID;
	}


	@Override
	public String toString() {
		return "AtomIndex: " + AtomIndex + "|" +
		"AtomTag: " + AtomTag + "|" +
		"NucType: " + NucType + "|" +
		"NucIndex: " + NucIndex + "|" +
		"StrandLabel: " + StrandLabel + "|" +
		"pos: " + new XYZPosition(X,Y,Z).toString()  + "|" +
		"UK1: " + UK1 + "|" +
		"UK2: " + UK2 + "|" +
		"StrandID: " + StrandID + "|" +
		"AtomTypeAbbr: " + AtomTypeAbbr;
		
	}
	
	
	

}
